//<SCRIPT language="javascript" src="Imaging.js"></SCRIPT>
var selCustList = null;
var txtCFN = null;
var txtAID = null;
var selCFL = null;
var xmlCFL = null;
var rsCFL  = null;
var elEncode = null;
function load_Page_NS(){

	txtCFN = F.txtApplID;
	txtCFN.onupdate = function(){ applID_changed(this) };
	txtCFN.onerror = function(){ _applID(null) };
	txtCFN.title = "Closing File Number";

	var div = document.createElement("DIV");
	div.id = "svcUo";
	document.body.appendChild(div);
	div.onreadystatechange = function(){onDivReadyChange(div)}
	div.addBehavior("/include/htc/webservice.htc");

	elEncode = document.createElement("DIV");
	document.body.appendChild(elEncode);
	//Locals
		//UO Web Service
	function onDivReadyChange(el){
		if( el.readyState != "complete" )return status = "Loading behavior ...";
		var WS_URL = 	location.protocol+"//"+location.host + "/WS/UO.asmx?WSDL";//"/WS/UO.asmx?WSDL";
		el.onserviceavailable = onUOAvailable
		el.useService(WS_URL,"UO");
	}
	function onUOAvailable(){
		uo = svcUo.UO;
		status = "UO behavior is loaded now.";
		loadClosingFileList();
	}
}
function loadClosingFileList(){
	var result = uo.callService(cb,"GetClosingFileListXML");
	//Locals
	function cb(o){
		if( showSOAPError(o,elEncode) )return location.reload();

		xmlCFL = document.createElement("XML");
		document.body.appendChild(xmlCFL);
		xmlCFL.loadXML(o.value);
		txtCFN.FillBox(xmlCFL.recordset);
		txtCFN.SELSIZE = 10;
		txtCFN.OFFSET_X = 2;
		txtCFN.OFFSET_Y = 2;
	}
}
function addClient(){
	var closingFile="";
	if( !(closingFile=prompt("Closing file name, pleace:","")) )return;
	var co = svcUo.createCallOptions("AddApplicant",undefined,false);
	var result = uo.callService(co,closingFile);
	if( showSOAPError(result,elEncode) )return;
	_CFN(closingFile);
	_applID(result.value);
	loadClosingFileList();
}
// Virtual functions
function menu_Page_V(menu){
	var a = new Array;
	menu.addMenu("-","");
	menu.menus.unshift(menu.menus.pop());
	menu.addMenu("New Client","addClient()");
	menu.menus.unshift(menu.menus.pop());
}
// Event handlers
	//*************************************
function applID_changed(txt){status = txt.sel.value;
	initFolders();
	if( !txt.value )return;
	var co = svcUo.createCallOptions("GetApplIDByClosingFile",undefined,false);
	var result = uo.callService(co,txt.value);
	if( showSOAPError(result,elEncode) ){
		_applID(null);
		return txt.focus();
	}
	_applID(result.value);
}
// Helpers
function initFolders(){
	ff.select(0,true);
	ff.showFiles(divFolders,false);
	showImage("about:blank");
}
// Properties
function _CFN(v){
	return defined(v) ? txtCFN.value = v : txtCFN.value;
}
function _applID(v){//Overwrite
	if( arguments.length ){
		txtCFN.applID = v;
		if( !v )initFolders();
	}
	return txtCFN.applID || 0;
}
